#include<bits/stdc++.h>
#define int long long 
 
using namespace std;

signed main() {
	map<int, vector<int>>mp;
	int ret = 0;
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i ++ ) {
		mp[s[i] - 'A'].push_back(i);
	}
	
	for(int i = 0; i < 26; i ++ ) {
		vector<int>v = mp[i];
		int n = v.size();
		for(int j = 1; j < n ; j ++ ) {
			ret += (v[j] - v[j - 1] - 1) * (v.size() - j) * (j);
			ret += (j * (v.size() - j - 1) );
		}
	}
	
	cout << ret << endl;
	return 0;
}

